<template>
  <el-card style="max-width: 99%">
    <template #header>
      <div class="card-header">
        <span>酒店推荐</span>
      </div>
    </template>
    <el-row style="margin-bottom: 20px">
      <el-col :span="5">
        <el-form :model="form" style="max-width: 200px;margin-left: 25px">
          <el-form-item label="酒店名称">
            <el-input v-model="name" placeholder="请输入酒店品牌" />
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="19">
        <el-button type="primary" @click="cx()">搜索</el-button>
        <el-button @click="cz()">重置</el-button>
      </el-col>
    </el-row>
    <el-table :data="list" border style="margin-bottom: 15px">
      <el-table-column prop="brand" label="酒店品牌" width="180" />
      <el-table-column prop="address" label="店铺位置" width="180" />
      <el-table-column prop="phone" label="电话" />
      <el-table-column prop="rank" label="酒店类型">
        <template #default="scope">
          <el-tag v-if="scope.row.rank==1" type="info">经济酒店</el-tag>
          <el-tag v-if="scope.row.rank==2" type="success">特惠酒店</el-tag>
          <el-tag v-if="scope.row.rank==3" type="warning">星级酒店</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="recommend" label="是否推荐">
        <template #default="scope">
          {{ scope.row.recommend === 1 ? '推荐' : '未推荐' }}
        </template>
      </el-table-column>
      <el-table-column prop="browse" label="浏览量" />
      <el-table-column prop="address" label="操作" >
        <template #default="scope1">
          <el-button :icon="Select" circle @click="updatePub(scope1.row)"/>
          <el-button :icon="CloseBold" circle  @click="updatePub2(scope1.row)"/>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin: 0 auto;width: 300px">
      <el-pagination @current-change="handleCurrentChange"
          size="small" background layout="prev, pager, next" :total="count" :page-size=pageSize class="mt-4"/>
    </div>
  </el-card>
</template>

<script>
import {selectAllPub, updatePub, updatePub2} from "@/api/vue3.js"
import {ElMessage, ElMessageBox} from "element-plus";
import {CloseBold, Select} from "@element-plus/icons-vue";
export default {
  name: 'Hotel2',
  computed: {
    Select() {
      return Select
    },
    CloseBold() {
      return CloseBold
    }
  },
  data(){
    return{
      name:'',//景点名称
      list:[],//景点列表
      count:0,//总条数
      pageSize:5,//每页条数
      pageNum:1,//当前页码
    }
  },
  mounted() {
    this.selectList()
  },
  methods:{
    cx(){
      this.name
      this.selectList()
    },
    cz(){
      this.name=''
      this.selectList()
    },
    selectList(){
      selectAllPub(this.name,this.pageNum,this.pageSize).then(res=>{
        this.list=res.data.data.list
        this.count=res.data.data.count
      })
    },
    handleCurrentChange(val) {//当前页码改变的事件
      this.pageNum = val;
      this.selectList()
    },
    updatePub(data){
      updatePub(data).then(res=>{
        if (res.data.code==200){
          ElMessage.success(res.data.msg)
          this.selectList()
        }else{
          ElMessage.error(res.data.msg)
        }
      })
    },
    updatePub2(data){
      updatePub2(data).then(res=>{
        if (res.data.code==200){
          ElMessage.success(res.data.msg)
          this.selectList()
        }else{
          ElMessage.error(res.data.msg)
        }
      })
    }
  },
}
</script>

<style scoped>
.el-card{
  width: 100%;
  height: 600px;
  background-color: white;
  margin-top: 20px;
  border-radius: 30px;
}
.el-table{
  margin: 0 auto;
  width: 96%;
}
</style>